package com.itheima.health.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.health.entity.TCheckgroupCheckitem;
import com.itheima.health.mapper.CheckItemDao;
import com.itheima.health.model.dtos.CheckItemDTO;
import com.itheima.health.model.pojos.CheckGroup;
import com.itheima.health.model.pojos.CheckItem;
import com.itheima.health.common.PageParam;
import com.itheima.health.common.ResultPageData;
import com.itheima.health.mapper.CheckItemDao;
import com.itheima.health.model.pojos.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;
    @Autowired
    private ITCheckgroupCheckitemService checkgroupCheckitemService;

    public ResultPageData findPage(PageParam pageParam) {
        Integer currentPage = pageParam.getCurrentPage();
        Integer pageSize = pageParam.getPageSize();
        IPage<CheckItem> page = new Page<>(currentPage, pageSize);
        LambdaQueryWrapper<CheckItem> query = new LambdaQueryWrapper<>();
        IPage<CheckItem> pageData = checkItemDao.selectPage(page, query);
        long total = pageData.getTotal();
        List<CheckItem> records = pageData.getRecords();
        ResultPageData resultPageData = new ResultPageData();
        resultPageData.setTotal(total);
        resultPageData.setRows(records);
        return resultPageData;
    }

    public void checkitemAdd(CheckItem checkItem) {
        checkItemDao.insert(checkItem);
    }

    public CheckItem checkitemById(Integer id) {
        CheckItem checkItem = checkItemDao.selectById(id);
        return checkItem;
    }

    public boolean checkItemUpdate(CheckItem checkItem) {
       int result = checkItemDao.updateById(checkItem);
       return result>0;
    }

    public void del(Integer id) {
        checkItemDao.deletecheckitemId(id);
    }


    /**
     * 根据检查组Id查出所有的检查项
     */
    public List<CheckItem> findCheckItemAll() {
        List<CheckItem> checkItems = checkItemDao.selectAll();
        return checkItems;
    }
}
